﻿using UnityEngine;
using System.Collections;

public class UIRound : MonoBehaviour {
	[SerializeField]Transform target;
	[SerializeField]float radius;
	public WrapMode warpMode;
	public float time;
	public bool _isPlay = false;
	// Use this for initialization
	void Start () {
		
	}
	// Update is called once per frame
	void Update () {
		if (time == 0)
			time = 1;
		if (_isPlay) {
			switch(warpMode){
			case WrapMode.Loop:
				Round ((Time.time%time)/time);
				break;
			case WrapMode.PingPong:
				Round (Mathf.PingPong (Time.time, time));
				break;
			default:
				Round(Mathf.Clamp(Time.time/time,0,0));
				break;
			}
		}
	}

	void Round(float anglepercent){
		Vector3 pos;
		float angle;
		angle = 360 * anglepercent;
		Quaternion q = Quaternion.AngleAxis (angle, Vector3.forward);
		pos =  q*Vector3.up*radius;
		target.localPosition = pos;
	}

	public void SetAniPlay(){
		_isPlay = true;
	}
	public void SetAniStop(){
		_isPlay = false;
	}


}
